package com.retrofit.library;

import com.retrofit.library.entity.Entity;

import java.util.Map;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Url;

/**
 * Desc:   如果想直接得到实体类，必须指定具体实体类，不能使用泛型。必须每个接口对应一个方法
 * Date:   2017/9/8 0008 10:28
 */

public interface ApiService {

    /**
     * @param path
     * @param params
     * @return 必须要指定具体类型，不能泛型，否则会报错：
     * “Caused by: java.lang.IllegalArgumentException:
     * Method return type must not include a type variable or wildcard: retrofit2.Call<T>”
     * <p>
     * 项目中还是以 String 返回，比较好拓展
     */
    @FormUrlEncoded
    @POST
    Call<String> post(@Url String path, @FieldMap Map<String, Object> params);

    @POST
    Call<String> post(@Url String path, @Header("loginToken") String loginToken,
                      @Body RequestBody body);


    @POST
    Call<ResponseBody> post2(@Url String path, @FieldMap Map<String, Object> params);

    @POST
    Call<ResponseBody> post2(@Url String path, @Header("loginToken") String loginToken,
                      @Body RequestBody body);
}
